#include "Utils.h"
#include "ListNode.h"
#include "TreeNode.h"
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Issue227 {
public:
	int calculate(string s) {
		int num=0;
		char sign='+';
		vector<int> valueStack;
		for (int i=0;i<s.length();++i)
		{
			char c=s[i];
			if (isdigit(c))
				num=num*10+c-'0';
			if ((c!=' '&&!isdigit(c))||(i==s.length()-1))
			{
				if (sign=='+')
					valueStack.push_back(num);
				if (sign=='-')
					valueStack.push_back(-num);
				if (sign=='*')
				{
					int v1=valueStack.back();
					valueStack.pop_back();
					valueStack.push_back(v1*num);
				}
				if (sign=='/')
				{
					int v1=valueStack.back();
					valueStack.pop_back();
					valueStack.push_back(v1/num);
				}
				sign=c;
				num=0;
			}
		}
		int res=0;
		for (int i=0;i<valueStack.size();++i)
			res+=valueStack[i];
		return res;
	}
};

int main227(){

	Issue227 sol;

	string s="1+2*3-4";
	cout<<sol.calculate(s)<<endl;

	return 0;
}